package com.easyedu.core.manager;

import com.easyedu.core.dao.OpenCourseTimeVersionDao;
import com.easyedu.core.entity.DeanServiceError;
import com.easyedu.core.entity.po.OpenCourseTimeVersion;
import com.easyedu.core.exception.EasyEduException;
import org.springframework.stereotype.Service;

/**
 * 排课版本公告逻辑类
 * @author linxi
 * @date 2022/4/17
 */
@Service
public class TimeTableVersionManager {

     private final OpenCourseTimeVersionDao openCourseTimeVersionDao;


     public TimeTableVersionManager(OpenCourseTimeVersionDao openCourseTimeVersionDao) {
          this.openCourseTimeVersionDao = openCourseTimeVersionDao;
     }

     public OpenCourseTimeVersion getTimeTableVersion(int openYear, String semester, String versionUUID) {
          OpenCourseTimeVersion openCourseTimeVersion =
                  openCourseTimeVersionDao.getByOpenYearAndVersionId(openYear, semester, versionUUID);
          if (openCourseTimeVersion == null || openCourseTimeVersion.getId() == 0) {
               throw new EasyEduException(DeanServiceError.ERR_OPEN_COURSE_TIME_VERSION_NOT_EXIST);
          }
          return openCourseTimeVersion;
     }
     public OpenCourseTimeVersion getTimeTableVersion(String versionUUID) {
          OpenCourseTimeVersion openCourseTimeVersion =
                  openCourseTimeVersionDao.getByVersionId(versionUUID);
          if (openCourseTimeVersion == null || openCourseTimeVersion.getId() == 0) {
               throw new EasyEduException(DeanServiceError.ERR_OPEN_COURSE_TIME_VERSION_NOT_EXIST);
          }
          return openCourseTimeVersion;
     }
}
